Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents chkPhilly As System.Windows.Forms.CheckBox Friend WithEvents chkNYC As System.Windows.Forms.CheckBox Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents TxtFuel As System.Windows.Forms.TextBox Friend WithEvents TxtPts As System.Windows.Forms.TextBox Friend WithEvents BtnDrive As System.Windows.Forms.Button Friend WithEvents BtnGetFuel As System.Windows.Forms.Button Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents TxtMoney As System.Windows.Forms.TextBox Friend WithEvents BtnQuit As System.Windows.Forms.Button Friend WithEvents btnGF As System.Windows.Forms.Button Private Sub InitializeComponent() Me.Label1 = New System.Windows.Forms.Label Me.chkPhilly = New System.Windows.Forms.CheckBox Me.chkNYC = New System.Windows.Forms.CheckBox Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.TxtFuel = New System.Windows.Forms.TextBox Me.TxtPts = New System.Windows.Forms.TextBox Me.BtnDrive = New System.Windows.Forms.Button Me.BtnGetFuel = New System.Windows.Forms.Button Me.Label4 = New System.Windows.Forms.Label Me.TxtMoney = New System.Windows.Forms.TextBox Me.BtnQuit = New System.Windows.Forms.Button Me.btnGF = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(176, 16) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(120, 23) Me.Label1.TabIndex = 0 Me.Label1.Text = "Silly Game" ' 'chkPhilly ' Me.chkPhilly.Checked = True Me.chkPhilly.CheckState = System.Windows.Forms.CheckState.Checked Me.chkPhilly.Location = New System.Drawing.Point(408, 40) Me.chkPhilly.Name = "chkPhilly" Me.chkPhilly.TabIndex = 1 Me.chkPhilly.Text = "Philly" ' 'chkNYC ' Me.chkNYC.Location = New System.Drawing.Point(408, 96) Me.chkNYC.Name = "chkNYC" Me.chkNYC.TabIndex = 2 Me.chkNYC.Text = "NYC" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(16, 72) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(40, 32) Me.Label2.TabIndex = 3 Me.Label2.Text = "Fuel:" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(16, 112) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(48, 32) Me.Label3.TabIndex = 4 Me.Label3.Text = "Points:" ' 'TxtFuel ' Me.TxtFuel.Location = New System.Drawing.Point(80, 72) Me.TxtFuel.Name = "TxtFuel" Me.TxtFuel.ReadOnly = True Me.TxtFuel.Size = New System.Drawing.Size(112, 20) Me.TxtFuel.TabIndex = 5 Me.TxtFuel.Text = "10" ' 'TxtPts ' Me.TxtPts.Location = New System.Drawing.Point(80, 112) Me.TxtPts.Name = "TxtPts" Me.TxtPts.ReadOnly = True Me.TxtPts.Size = New System.Drawing.Size(112, 20) Me.TxtPts.TabIndex = 6 Me.TxtPts.Text = "0" ' 'BtnDrive ' Me.BtnDrive.Location = New System.Drawing.Point(16, 200) Me.BtnDrive.Name = "BtnDrive" Me.BtnDrive.Size = New System.Drawing.Size(96, 32) Me.BtnDrive.TabIndex = 7 Me.BtnDrive.Text = "Drive" ' 'BtnGetFuel ' Me.BtnGetFuel.Location = New System.Drawing.Point(128, 200) Me.BtnGetFuel.Name = "BtnGetFuel" Me.BtnGetFuel.Size = New System.Drawing.Size(96, 32) Me.BtnGetFuel.TabIndex = 8 Me.BtnGetFuel.Text = "Get Fuel" ' 'Label4 ' Me.Label4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label4.Location = New System.Drawing.Point(16, 152) Me.Label4.Name = "Label4" Me.Label4.Size = New System.Drawing.Size(48, 32) Me.Label4.TabIndex = 9 Me.Label4.Text = "Money:" ' 'TxtMoney ' Me.TxtMoney.Location = New System.Drawing.Point(80, 152) Me.TxtMoney.Name = "TxtMoney" Me.TxtMoney.ReadOnly = True Me.TxtMoney.Size = New System.Drawing.Size(112, 20) Me.TxtMoney.TabIndex = 10 Me.TxtMoney.Text = "10" ' 'BtnQuit ' Me.BtnQuit.Location = New System.Drawing.Point(240, 200) Me.BtnQuit.Name = "BtnQuit" Me.BtnQuit.Size = New System.Drawing.Size(96, 32) Me.BtnQuit.TabIndex = 11 Me.BtnQuit.Text = "Quit" ' 'btnGF ' Me.btnGF.Location = New System.Drawing.Point(368, 176) Me.btnGF.Name = "btnGF" Me.btnGF.Size = New System.Drawing.Size(112, 32) Me.btnGF.TabIndex = 12 Me.btnGF.Text = "Get Fuel" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(576, 273) Me.Controls.Add(Me.btnGF) Me.Controls.Add(Me.BtnQuit) Me.Controls.Add(Me.TxtMoney) Me.Controls.Add(Me.Label4) Me.Controls.Add(Me.BtnGetFuel) Me.Controls.Add(Me.BtnDrive) Me.Controls.Add(Me.TxtPts) Me.Controls.Add(Me.TxtFuel) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.chkNYC) Me.Controls.Add(Me.chkPhilly) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Const fuelToTravel As Double = 1.0 Const ptsForTravel As Double = 3.0 Const fuelCost As Double = 2.0 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub BtnGetFuel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnGetFuel.Click ' first see if there is enough money Dim fuel As Double Dim points As Double Dim money As Double fuel = Convert.ToDouble(TxtFuel.Text) 'money = Convert.ToDouble(TxtMoney.Text) money = Convert.ToDouble(TxtMoney.Text.TrimStart("$")) If money >= fuelCost Then ' we can buy gas ' increase fuel and decrease money fuel = fuel + 1 TxtFuel.Text = fuel.ToString("n1") money = money - fuelCost TxtMoney.Text = money.ToString("c") Else MsgBox("Sorry you do not have enough money to buy gas") End If End Sub Private Sub BtnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnQuit.Click Me.Close() End Sub Private Sub BtnDrive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDrive.Click ' first see if there is enough fuel Dim fuel As Double Dim points As Double fuel = Convert.ToDouble(TxtFuel.Text) If (fuel >= fuelToTravel) Then ' we can travel ' figure out where going If chkPhilly.Checked = True Then chkPhilly.Checked = False chkNYC.Checked = True Else ' must be in NY, go to philly chkPhilly.Checked = True chkNYC.Checked = False End If ' reduce fuel and increase points fuel = fuel - fuelToTravel TxtFuel.Text = fuel.ToString("n1") points = Convert.ToDouble(TxtPts.Text) points = points + ptsForTravel TxtPts.Text = points.ToString("n1") Else MsgBox("Sorry you do not have enough gas to travel") End If ' End Sub Private Sub btnGF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGF.Click Dim amtFuel As Double Dim amtMoney As Double ' convert current values to variables amtFuel = Convert.ToDouble(TxtFuel.Text) amtMoney = Convert.ToDouble(TxtMoney.Text) ' check if we have enough money If amtMoney >= fuelCost Then amtMoney = amtMoney - fuelCost amtFuel = amtFuel + fuelToTravel 'display results TxtFuel.Text = amtFuel.ToString("n1") TxtMoney.Text = amtMoney.ToString("n2") Else MsgBox("Sorry you don't have enough money " & Environment.NewLine & "Please visit an ATM" _ , MsgBoxStyle.OKOnly, "Money Warning") End If End Sub End Class